const state = {
  memo: {
    memoModal: false,
    source: '', // 弹窗修改的哪个资源
    id: '', // 哪个资源下的哪个id数据
    name: '' // 哪个资源下的哪个字段
  },
  shop: {
    shopModal: false,
    source: '', // 弹窗修改的哪个资源
    id: '', // 哪个资源下的哪个id数据
    name: '' // 哪个资源下的哪个字段
  }
}
const mutations = {
  changememoModal (state, payload) {
    if (payload.source) {
      state.memo = Object.assign(state.memo, payload)
    }
    state.memo.memoModal = !state.memo.memoModal
  },
  changeShopModal (state, payload) {
    if (payload.source) {
      state.shop = Object.assign(state.shop, payload)
    }
    state.shop.shopModal = !state.shop.shopModal
  }
}
const actions = {
  changeSourceData ({ state, commit, rootState }, data) {
    let { id, source, name } = state.memo
    let dataArr = rootState[source][name]
    dataArr.forEach((item, index, arr) => {
      if (item.id === id) {
        arr[index].value = data
      }
    })
    commit('changememoModal', {})
  },

  changeSourceShopData ({ state, commit, rootState }, data) {
    let { id, source, name } = state.shop
    let dataArr = rootState[source][name]
    dataArr.forEach((item, index, arr) => {
      if (item.id === id) {
        arr[index].value = data
      }
    })
    commit('changeShopModal', {})
  }
}
export default {
  state,
  mutations,
  actions
}
